package cn.edu.scau.cmi.zhengweibo.client.controller;

import javafx.fxml.FXML;

import javafx.scene.control.Button;

import javafx.scene.text.Text;

import javafx.scene.control.TextField;
import cn.edu.scau.cmi.zhengweibo.composite.consistent.ConsistentComponent;
import cn.edu.scau.cmi.zhengweibo.composite.consistent.ConsistentComposite;
import cn.edu.scau.cmi.zhengweibo.composite.consistent.ConsistentLeaf;
import javafx.event.ActionEvent;

import javafx.scene.control.TextArea;

public class ConsistentCompositeViewController {
	@FXML
	private Button addbtn;
	@FXML
	private Button delbtn;
	@FXML
	private Button p_addbtn;
	@FXML
	private Button findbtn;
	@FXML
	private Button modifybtn;
	@FXML
	private TextField tf1;
	@FXML
	private TextField tf2;
	@FXML
	private TextField tf3;
	@FXML
	private TextField tf4;
	@FXML
	private TextArea textarea;
	@FXML
	private Button backbtn;

	ConsistentComposite root = new ConsistentComposite("学校");
	ConsistentComposite newcomposite = root;
	ConsistentComposite new2composite = null;
	ConsistentComponent deletecomponent = null;
	@FXML
	public void add(ActionEvent event) {
		new2composite = new ConsistentComposite(tf1.getText());
		newcomposite.add(new2composite);
		newcomposite = new2composite;
	}
	
	@FXML
	public void delete(ActionEvent event) {
		deletecomponent = newcomposite.find(tf1.getText());
		if(deletecomponent!=null) {
			newcomposite.remove(deletecomponent);
		}
	}
	
	@FXML
	public void addPeople(ActionEvent event) {
		newcomposite.add(new ConsistentLeaf(tf2.getText()));
	}
	
	@FXML
	public void find(ActionEvent event) {
		textarea.setText(root.show1(""));
	}
	
	@FXML
	public void modify(ActionEvent event) {
		deletecomponent = newcomposite.find(tf3.getText());
		if(deletecomponent!=null) {
			deletecomponent.name = tf4.getText();
		}
	}
	
	@FXML
	public void backToRoot(ActionEvent event) {
		newcomposite = root;
	}
}
